<?php

class UserAction extends Action {
	
	public function registerCheck() {
		$msg = D( 'Plat/User' )->c();
		if ( $msg=='success' ) {
			$this->success( '注册成功！', U( 'Home/Index/index' ) );
		}
		else $this->error( $msg );
	}
	
	public function loginCheck() {
		if ( session( 'uid' )!=null ) {
			$this->success( '登录成功！', U( 'Home/Index/index' ) );
			return;
		}

		$userInfo = D( 'Plat/User' )->rByName( $this->_post( 'name' ) );
		if ( $userInfo!=null && $userInfo['password']==encrypt( $this->_post( 'pass' ) ) ) {
			session( 'uid', $userInfo['id'] );
			session( 'name', $userInfo['name'] );
			session( 'school', $userInfo['school'] );
			
			$this->success( '登录成功！', U( 'Home/Index/index' ) );
			return;
		}
		else {
			$this->error( '账号或密码不正确' );
			return;
		}
	}
	
	public function logout() {
		session( 'uid', null );
		$this->success( '登出成功！' );
	}
}